package com.yanqu.road.entity.curio;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@FieldTypeAnnotation(tableName = "t_u_curio", desc = "藏宝主数据")
public class UserCurioData extends DataObject {

    @FieldTypeAnnotation(desc = "用户ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "评分")
    private long score;

    @FieldTypeAnnotation(desc = "勋章等级")
    private int badgeLv;

    @FieldTypeAnnotation(desc = "抽奖次数")
    private int drawTimes;

    @FieldTypeAnnotation(desc = "品质抽奖次数")
    private Map<Integer, Integer> qualityDrawTimesMap;

    @FieldTypeAnnotation(desc = "评分变更时间")
    private int scoreUpdateTime;

    @FieldTypeAnnotation(desc = "山河进度")
    private long riverProcess;

    @FieldTypeAnnotation(desc = "激活的特权")
    private List<Integer> privilegeList;

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if(this.score != score) {
            this.score = score;
            setUpdateOption();
        }
    }

    public int getBadgeLv() {
        return badgeLv;
    }

    public void setBadgeLv(int badgeLv) {
        if(this.badgeLv != badgeLv) {
            this.badgeLv = badgeLv;
            setUpdateOption();
        }
    }

    public int getDrawTimes() {
        return drawTimes;
    }

    public void setDrawTimes(int drawTimes) {
        if(this.drawTimes != drawTimes) {
            this.drawTimes = drawTimes;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getQualityDrawTimesMap() {
        return qualityDrawTimesMap;
    }

    public void setQualityDrawTimesMap(Map<Integer, Integer> qualityDrawTimesMap) {
        this.qualityDrawTimesMap = qualityDrawTimesMap;
    }

    public int getQualityDrawTimes(int quality){
        if(qualityDrawTimesMap == null){
            qualityDrawTimesMap = new HashMap<>();
        }
        return qualityDrawTimesMap.getOrDefault(quality, 0);
    }

    public void addQualityDrawTimes(int quality, int times){
        int old = qualityDrawTimesMap.getOrDefault(quality, 0);
        qualityDrawTimesMap.put(quality, times + old);
    }

    public void restQualityDrawTimes(int quality){
        if(qualityDrawTimesMap.containsKey(quality)){
            qualityDrawTimesMap.put(quality, 0);
            setUpdateOption();
        }
    }

    public int getScoreUpdateTime() {
        return scoreUpdateTime;
    }

    public void setScoreUpdateTime(int scoreUpdateTime) {
        if(this.scoreUpdateTime != scoreUpdateTime) {
            this.scoreUpdateTime = scoreUpdateTime;
            setUpdateOption();
        }
    }

    public long getRiverProcess() {
        return riverProcess;
    }

    public void setRiverProcess(long riverProcess) {
        if(this.riverProcess != riverProcess) {
            this.riverProcess = riverProcess;
            setUpdateOption();
        }
    }
}
